#!/usr/bin/env bash

set -ex

export CURRENT_VERSION=$1;
export NODE_ENV=production;

corepack enable;
corepack install || exit 1;
yarn install || exit 1;
rm -rf target

# Build the application
yarn run build;

# Copy package*.json files
cp ../.yarnrc.yml target/;
cp yarn.lock target/;
cp package.json target/;

cat <<EOF | tee target/setup
#/usr/bin/env bash
set -e;
corepack enable;
corepack install;
yarn install
yarn run playwright install chromium;
EOF

chmod +x target/setup;

sed -i -re "s/\%version\%/$CURRENT_VERSION/g" ./target/app.js;
